package InternetProgram;

import java.io.*;
import java.net.*;
import java.security.cert.TrustAnchor;

/**
 * @ClassName: ProgramReceive
 * @Auther: Drawin
 * @Date: 2021/11/22 16:49
 * @Description:
 */

public class ProgramReceive extends Thread{
    Socket s;
    DataInputStream din;
    public ProgramReceive(Socket s){
        this.s=s;
        try {
            din=new DataInputStream(s.getInputStream());
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public void run(){
        while (true){
            try {
                String tmp=din.readUTF();
                System.out.println("对方说："+tmp);
                if (tmp.trim().equals("bye")){
                    din.close();s.close();break;
                }
            }catch (IOException e){
                System.out.println("接受数据失败："+e.getMessage());
                try {
                    s.close();
                }catch (IOException e1){
                    e1.printStackTrace();
                }
                break;
            }
        }
    }
}
